home *** CD-ROM | disk | FTP | other *** search
- /* from Dale Schumacher's dLibs */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <memory.h>
-
- int fclose(fp)
- register FILE *fp;
- {
- register unsigned int f;
- register int error = 0;
-
- if(fp == NULL)
- return(EOF); /* NULL file pointer file */
- f = fp->_flag;
- if((f & (_IORW | _IOREAD | _IOWRT)) == 0)
- return(EOF); /* file not open! */
- if(f & (_IOWRT | _IORW)) /* only bother flushing for write */
- error = fflush(fp);
- if(!(f & _IOMYBUF)) /* throw away non-standard buffer */
- {
- fp->_base = NULL;
- fp->_ptr = NULL;
- fp->_bsiz = 0;
- }
- else
- {
- free(fp->_base);
- fp->_base = NULL;
- fp->_ptr = NULL;
- fp->_bsiz = 0;
- }
- fp->_flag = 0; /* clear status */
- error |= close(fp->_file);
- return(error ? EOF : 0);
- }
-